(function() {
	var assetPage = {
		init:function() {
			this.eventCenter();
			this.getUserFund();
			this.getUserProfitList();
		},
		eventCenter: function() {
			$('.one_block').hover(function() {
				$(this).find('.ob_icon').addClass('hover');
			},function() {
				$(this).find('.ob_icon').removeClass('hover');
			});
		},
		getUserFund: function() {
			var me = this;
			$.getJSON('/user/userfundsummary',function(data) {
				if(data && data.error_no==0 && data.data) {
					// var data = {"error_no":0,"data":{"total":21.73332,"bought_amount":"18.000000000000000000","waiting_amount":0,"profit":"3.733320000000000000","freeze":"0.000000000000000000","yesterday_profit":"1.2","total_profit":"5.200000000000000000"}};
					$('#bought_amount .ob_title').text('￥' + mathUtil.formatAmount(data.data.bought_amount,0));
					$('#waiting_amount .ob_title').text('￥' + mathUtil.formatAmount(data.data.waiting_amount,0));
					$('#freeze .ob_title').text('￥' + mathUtil.formatAmount(data.data.freeze,4));
					$('#profit .ob_title').text('￥' + mathUtil.formatAmount(data.data.profit,4));
					$('#yesterday_profit .ob_title').text('￥' + mathUtil.formatAmount(data.data.yesterday_profit));
					$('#summary_profit .ob_title').text('￥' + mathUtil.formatAmount(data.data.total_profit));
					me.renderPie(data.data);
				} else {
					if(data.error_no != 0) {
						alert(data.error_message);
					}
				}
			});
		},
		getUserProfitList :function() {
			var me = this;
			$.getJSON('/user/userprofitlist',function(data) {
				// data = {"error_no":0,"data":[{"date":"1405958400","profit":"2.799990000000000000"},{"date":"1403958400","profit":"2.799990000000000000"},{"date":"1402958400","profit":"2.799990000000000000"},{"date":"1401958400","profit":"2.799990000000000000"}]};
				if(data && data.error_no==0) {
					me.renderProfitList(data.data);
				} else {
					if(data.error_no != 0) {
						alert(data.error_message);
					}
				}
			});
		},

		renderPie : function(data) {
			$('.cycle').highcharts({
				chart : {
					backgroundColor:'rgba(0,0,0,0)',
					borderColor:"#AAA"
				},
				credits : {
					enabled:false
				},
				title: {
					userHTML : true,
					text: '<div style="color:#FFF;font-style:italic;font-size:30px">'+'￥' + mathUtil.formatAmount(data.total,4)+ '</div>',
					color:'#FFF',
					align: 'center',
					verticalAlign: 'middle',
					y: -10
				},
				subtitle : {
					userHTML : true,
					text: '<div style="font-size:14px;padding-top:30px;color:#336">资金总额</div>',
					verticalAlign:'middle',
					y:20
				},
				tooltip: {
					pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
				},
				legend: {
					borderColor: '#909090'
				},
				plotOptions: {
					pie: {
						borderWidth:"0px",
						size:"75%",
						dataLabels: {
							enabled: true
						}
					}
				},

				series: [{
					type: 'pie',
					name: '占比',
					innerSize: '100%',
					data :[
						{
							name:'已购的真融宝资金',
							y:parseFloat(data.bought_amount),
							dataLabels : {
								enabled:false
							},
							color:'#336'
						},
						{
							name:'收益资金',
							y:parseFloat(data.profit),
							dataLabels : {
								enabled:false
							},
							color:'#54548b'
						},
						{
							name:'排队资金',
							y:parseFloat(data.waiting_amount),
							dataLabels : {
								enabled:false
							},
							color:'#6f6faa'
						},
						{
							name:'冻结资金',
							y:parseFloat(data.freeze),
							dataLabels : {
								enabled:false
							},
							color:'#ccccff'
						}
					]
				}]
			});
		},
		renderProfitList:function(data) {
			var date_list = [];
			var profit_list = [];
			if(data.length == 0) {
				// var text = "快来进行投资吧，即刻产生收益。";
				// $('.profit_list').append(text);
				$('#profit_info').css('display','none');
				return;
			} else {
				for (var i = 0; i < data.length; i++) {
					date_list.push(new Date(data[i].date * 1000).pattern('MM-dd'));
					profit_list.push(parseFloat(data[i].profit));
				};
			}
			$('.profit_list').highcharts({
	    		credits : {
	    			enabled:false
	    		},
	            title: {
	                text: ' ',
	                x: -20 //center
        	    },
			    legend: {
		            align: 'center',
		            verticalAlign: 'top',
		            x: 300,
		            y: 0
		        },
        	    xAxis: {
        	    	type:'datetime',
                	categories: date_list,
                	gridLineWidth: 1 ,//图形的背景线设置
            		lineWidth : 1 //Y轴的宽度
            	},
            	yAxis: {
            		gridLineWidth: 1 ,//图形的背景线设置
            		lineWidth : 1, //Y轴的宽度
	                title: {
	                    text: '每日收益金额'
	                },
	                // categories : [0,10,20]
	                plotLines: [{
	                    value: 0,
	                    width: 1,
	                    color: '#808080'
	                }]
	            },
			    tooltip: {
	                valuePrefix: '￥'
	            },
	            plotOptions : {
			        series: {
                		fillOpacity: 0.2
            		}
	            },
	            series: [{
	            	type : 'line',
	                name: '我的收益',
	                data: profit_list,
	                color:'#F93'
            	}]
			});
		}
	};
	assetPage.init();
})();